package com.example.bookstore.controller;

import com.example.bookstore.common.BaseContext;
import com.example.bookstore.common.Result;

import com.example.bookstore.entity.Addressee;
import com.example.bookstore.service.AddresseeService;
import com.sun.xml.internal.ws.wsdl.writer.document.http.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddresseeController {
    @Autowired
    AddresseeService addresseeService;
    @GetMapping("/list")
    public Result getAddress(){
        int currentId = BaseContext.getCurrentId();
        Result stringResult = addresseeService.getAddress(currentId);
        return stringResult;
    }
    @PutMapping
    public Result<String> addAddress(@RequestBody Addressee address){
        Result<String> stringResult = addresseeService.addAddress(address);
        return stringResult;
    }
    @PostMapping
    public Result<String> updateAddress(@RequestBody  Addressee address){
        Result<String> stringResult = addresseeService.updateAddress(address);
        return stringResult;
    }
    @DeleteMapping("/{id}")
    public Result<String> deleteAddress(@PathVariable Integer id){
        Result<String> stringResult = addresseeService.deleteAddress(id);
        return stringResult;
    }
}
